class Solution {
    public: 
        int ret =0,path =0;
        int is_existent[50][50] = {0};
        int maxAreaOfIsland(vector<vector<int>>& grid) {
            int n = grid.size(),m = grid[0].size();
            for(int i = 0 ; i < n ; i++){
                for(int j = 0 ; j < m ; j++){
                    if(grid[i][j] == 1){
                        grid[i][j] = 0;
                        is_existent[i][j] = 1;
                        path = 0;
                        path++;
                        dfs(grid,i,j);
                    }
                }
            }
            return ret;
        }
        int indexx[4]={0,0,1,-1};
        int indexy[4]={1,-1,0,0};
        void dfs(vector<vector<int>>& grid,int i,int j){
            int n = grid.size(),m=grid[0].size();
            for(int k = 0; k < 4 ;k++){
                int row = i+ indexx[k];
                int col = j+indexy[k];
                if(row >=0&&row <n && col >=0&& col<m && is_existent[row][col] == 0&&grid[row][col] ==1){
                    is_existent[row][col] = 1;;
                    grid[row][col] = 0;
                    path++;
                    dfs(grid,row,col);
                }
            }
            ret = max(ret,path);
            return; 
        }
    };